/**
 * 
 */
package demo.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author roger.xu
 * 
 */
public class PropertiesUtils {
    private static final Log _log = LogFactory.getLog(PropertiesUtils.class.getSimpleName());

    private static final String NEW_LINE = System.getProperty("line.separator");

    private static Properties properties = null;
    static {
        try {
            final ClassLoader classLoader = PropertiesUtils.class.getClassLoader();
            final InputStream in = classLoader.getResourceAsStream("derby.properties");
            properties = new Properties();
            properties.load(in);
        } catch (final IOException e) {
            _log.error("error when loading derby.properties");
            throw new IllegalStateException(e);
        }
    }

    public static void load(final String path) {
        try {
            final ClassLoader classLoader = PropertiesUtils.class.getClassLoader();
            final InputStream in = classLoader.getResourceAsStream(path);
            properties = new Properties();
            properties.load(in);
        } catch (final IOException e) {
            _log.error("error when loading " + path);
            throw new IllegalStateException(e);
        }
    }

    public static void test() {
        final String username = properties.getProperty("username");
        Console.getInstance().debug(username);
    }
}
